package com.csjy.migration.hnnd.business;

import com.csjy.migration.hnnd.DbUtil;
import com.csjy.migration.hnnd.ProgramArgument;
import com.csjy.migration.hnnd.annotation.BusinessDataConverter;

import java.sql.SQLException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public abstract class AbstractWorkflowBusiness extends AbstractBusiness {
  protected String procInstId = null;
  protected Map<String, Map<String,Object>> taskParamMap = new HashMap<>();

  public Map<String, Map<String, Object>> getTaskParamMap() {
    return taskParamMap;
  }

  public void setTaskParamMap(Map<String, Map<String, Object>> taskParamMap) {
    this.taskParamMap = taskParamMap;
  }


  public AbstractWorkflowBusiness(DbUtil sourceDbUtil, DbUtil targetDbUtil, SourceBusinessData sourceData, ProgramArgument programArgument, String projectId, String procInstId) throws SQLException {
    super(sourceDbUtil, targetDbUtil, sourceData, programArgument, projectId, true);
    this.procInstId = procInstId;
    this.findMigratedIdList();
  }

  @Override
  public void findMigratedIdList() throws SQLException {
    BusinessDataConverter businessDataConverter = this.getClass().getAnnotation(BusinessDataConverter.class);
    // 查询已迁移的记录
    this.migratedIdList = this.targetDbUtil.selectSingleColumn(businessDataConverter.findMigratedIdListSql(),
        Arrays.asList(new String[]{this.procInstId + "-JW"}));
  }
}
